package com.zcl.entity;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Date;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * .
 *
 * @Author Chenglin Zhu
 * @Date 2021/6/25 11:12
 */
@Data
@AllArgsConstructor
public class Order implements Delayed {
    //订单编号
    private String orderNO;
    //过期时间
    private Date time;
    //订单状态
    private String orderStatus;

    // 设置延时时间
    @Override
    public long getDelay(TimeUnit unit) {
        long l = unit.convert(time.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
        return l;
    }

    @Override
    public int compareTo(Delayed o) {
        //根据取消时间来比较，如果取消时间小的，就会优先被队列提取出来
        return time.compareTo(((Order) o).getTime());
    }
}
